Requires Scripting PRO
The SFTPClient class provides access to the remote file system over an SSH connection using the SFTP protocol. It supports common file operations such as reading directories, managing files and folders, retrieving file attributes, and resolving real paths.
This class is returned by the method SSHClient.openSFTP().
readonly isActive: booleanIndicates whether the SFTP connection is still open.
true: The connection is active and usable.false: The connection has been closed or interrupted.close(): Promise<void>Closes the SFTP connection.
Promise that resolves when the connection is successfully closed.readDirectory(atPath: string): Promise<string[]>Reads the contents of a directory at the specified path.
atPath (string):
The remote directory path to read.Promise that resolves to an array of file and directory names within the directory.createDirectory(atPath: string): Promise<void>Creates a new directory at the given path.
atPath (string):
The path where the new directory should be created.Promise that resolves when the directory is created successfully.removeDirectory(atPath: string): Promise<void>Removes the directory at the specified path.
atPath (string):
The path of the directory to remove.Promise that resolves when the directory is removed.rename(oldPath: string, newPath: string): Promise<void>Renames a file or directory.
oldPath (string):
The current file or directory path.
newPath (string):
The desired new path.
Promise that resolves when the item is successfully renamed.getAttributes(atPath: string): Promise<{ ... }>Retrieves metadata for a file or directory.
atPath (string):
The file or directory path to inspect.A Promise that resolves to an object containing:
size?: number: File size in bytesflag?: number: Internal flaguserId?: number: User IDgroupId?: number: Group IDaccessTime?: Date: Last access timemodificationTime?: Date: Last modification timepermissions?: number: File mode/permissions (e.g., 0o755)readFile(atPath: string): Promise<string>Reads the contents of a file as a string.
atPath (string):
The file path to read.Promise that resolves to the file content as a UTF-8 string.writeFile(atPath: string, content: string): Promise<void>Writes content to a file. If the file already exists, it will be overwritten.
atPath (string):
The destination file path.
content (string):
The text content to write.
Promise that resolves when the file is written successfully.removeFile(atPath: string): Promise<void>Removes a file at the specified path.
atPath (string):
The file path to remove.Promise that resolves when the file is deleted.getRealPath(atPath: string): Promise<string>Resolves the canonical (real) path for a given file or directory path on the remote system.
atPath (string):
The input path, possibly containing symbolic links or relative segments.Promise that resolves to the absolute, resolved path.